﻿#include "samplewindow.h"
#include "ui_samplewindow.h"
#include "QStandardPaths"

extern intListener doorStatus;
SampleWindow::SampleWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SampleWindow)
{
    ui->setupUi(this);
    setWindowIcon(QIcon(":/pic/picture/kafavicon.ico"));
    ui->pushButton_7->hide();
    ui->pushButton_8->hide();
    ui->label_4->hide();

    ui->SampleName->setEditable(true);

    tcpClient = TcpClient::getInstance();
    logClient =loghelper::getInstance();

    QObject::connect(&MainWindow::experimentStatus, &intListener::valueChanged,this,&SampleWindow::changeToMainWindow,Qt::QueuedConnection);
    QObject::connect(&MainWindow::tcpServerStatus, &intListener::valueChanged,this,&SampleWindow::changeToMainWindow,Qt::QueuedConnection);
    QObject::connect(&MainWindow::startExperiment, &intListener::valueChanged,this,&SampleWindow::oneMachineStartExperiment,Qt::QueuedConnection);
    QObject::connect(&MainWindow::startExperimentStatus, &intListener::valueChanged,this,&SampleWindow::experimentStatusChanged,Qt::DirectConnection);

    //创建表单
    QStringList  colLabels;
    colLabels<<QStringLiteral("1")<<QStringLiteral("2") << QStringLiteral("3") << QStringLiteral("4") ;
    ui->tableWidget->setColumnCount(4);
    ui->tableWidget->setHorizontalHeaderLabels(colLabels);

    QStringList  rowlabels;
    rowlabels<<QStringLiteral("A")<<QStringLiteral("B") << QStringLiteral("C") << QStringLiteral("D") << QStringLiteral("E")<<QStringLiteral("F");
    ui->tableWidget->setRowCount(6);
    ui->tableWidget->setVerticalHeaderLabels(rowlabels);

    ui->tableWidget->resizeColumnsToContents(); //根据内容调整列宽
    ui->tableWidget->resizeRowsToContents();

    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->verticalHeader()->setStretchLastSection(true);
    ui->tableWidget->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->verticalHeader()->setMinimumWidth(30);
    ui->pushButton_3->setVisible(false);

    QRegExp regExp("^?(100|([1-9]?\\d|1[0-7][0-9])(.\\d{1,2})?)$");
    QRegExpValidator *validator2 = new QRegExpValidator(regExp, this);
    ui->SampleConc->setValidator(validator2);
}
SampleWindow::~SampleWindow()
{
    delete ui;
}

void SampleWindow::on_returnBtn_clicked()
{
    this->close();
    emit changeExpInfoWindow();
}

void SampleWindow::showEvent(QShowEvent *event)
{
    tcpClient = TcpClient::getInstance();
    logClient =loghelper::getInstance();

    if(MainWindow::HoleNum==192){
        ui->NextBtn->show();
    }else {
        ui->NextBtn->hide();
    }
    ui->label_4->hide();

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    QString sql="Select Name from ItemCode Where DicCode='7' and IsDefault='1'";
    query.exec(sql);
    while (query.next()) {
        ui->checkBox->setText(query.value("Name").toString());
    }

    sql="Select Name from ItemCode Where DicCode='8' and IsDefault='1'";
    query.exec(sql);
    while (query.next()) {
        ui->checkBox_2->setText(query.value("Name").toString());
    }

    sql="Select Name from ItemCode Where DicCode='9' and IsDefault='1'";
    query.exec(sql);
    while (query.next()) {
        ui->checkBox_4->setText(query.value("Name").toString());
    }

    sql="Select Name from ItemCode Where DicCode='10' and IsDefault='1'";
    query.exec(sql);
    while (query.next()) {
        ui->checkBox_3->setText(query.value("Name").toString());
    }

    ui->SampleName->blockSignals(true);
    ui->SampleName->clear();

    sql="Select Name from ItemCode Where DicCode='1'";
    query.exec(sql);
    while (query.next()) {
        ui->SampleName->addItem(query.value("Name").toString());
    }

    ui->SampleName->blockSignals(false);

    ui->SampleType->blockSignals(true);
    ui->SampleType->clear();

    sql="Select Name from ItemCode Where DicCode='2'";
    query.exec(sql);
    while (query.next()) {
        ui->SampleType->addItem(query.value("Name").toString());
    }

    ui->SampleType->blockSignals(false);

    sql="Select ExperimentName From ExperimentInfo";
    query.exec(sql);
    while (query.next()) {
        ui->label_10->setText(query.value("ExperimentName").toString());
    }

    if(MainWindow::experimentStatus.get()==0){
        ui->pushButton_7->hide();
        ui->pushButton_8->hide();

        ui->BeginBtn->setEnabled(true);
        ui->SaveBtn->setEnabled(true);
        ui->ClearBtn->setEnabled(true);
        ui->returnBtn->setEnabled(true);

        ui->SampleConc->setEnabled(true);
        ui->SampleName->setEnabled(true);
        ui->SampleType->setEnabled(true);

        ui->checkBox->setEnabled(true);
        ui->checkBox_2->setEnabled(true);
        ui->checkBox_3->setEnabled(true);
        ui->checkBox_4->setEnabled(true);

        ui->LoadAllBtn->setEnabled(true);
        ui->CancelLoadBtn->setEnabled(true);

        if(doorStatus.get()==0)
        {
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/t10.png);background-color: rgba(0, 0, 0, 0.3);");
        }
        else
        {
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/t11.png);background-color: rgba(0, 0, 0, 0.3);");
        }


        RefreshSampleInfo();
    }
    else if(MainWindow::experimentStatus.get()==1){
        ui->pushButton_7->show();
        ui->pushButton_8->show();
        ui->BeginBtn->setEnabled(false);
        ui->SaveBtn->setEnabled(false);
        ui->ClearBtn->setEnabled(false);
        ui->returnBtn->setEnabled(false);

        ui->SampleConc->setEnabled(false);
        ui->SampleName->setEnabled(false);
        ui->SampleType->setEnabled(false);

        ui->checkBox->setEnabled(false);
        ui->checkBox_2->setEnabled(false);
        ui->checkBox_3->setEnabled(false);
        ui->checkBox_4->setEnabled(false);

        ui->LoadAllBtn->setEnabled(false);
        ui->CancelLoadBtn->setEnabled(false);

        ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/jy5.png);background-color: rgba(0, 0, 0, 0.3);");
        RefreshSampleInfo();
    }
    else if(MainWindow::experimentStatus.get()==4){
        sql="Select ID From ExperimentInfo";
        query.exec(sql);
        while (query.next()) {
            MainWindow::experimentGuid=query.value("ID").toString();
        }

        ui->BeginBtn->setEnabled(false);
        ui->SaveBtn->setEnabled(false);
        ui->ClearBtn->setEnabled(false);
        ui->returnBtn->setEnabled(true);

        ui->SampleConc->setEnabled(false);
        ui->SampleName->setEnabled(false);
        ui->SampleType->setEnabled(false);

        ui->checkBox->setEnabled(false);
        ui->checkBox_2->setEnabled(false);
        ui->checkBox_3->setEnabled(false);
        ui->checkBox_4->setEnabled(false);

        ui->LoadAllBtn->setEnabled(false);
        ui->CancelLoadBtn->setEnabled(false);

        ui->pushButton_7->show();
        ui->pushButton_8->show();
        RefreshSampleInfo();
    }
    else if(MainWindow::experimentStatus.get()==5){
        sql="Select ID From ExperimentInfo";
        query.exec(sql);
        while (query.next()) {
            MainWindow::experimentGuid=query.value("ID").toString();
        }

        ui->pushButton_7->hide();
        ui->pushButton_8->hide();

        ui->BeginBtn->setEnabled(true);
        ui->SaveBtn->setEnabled(true);
        ui->ClearBtn->setEnabled(true);
        ui->returnBtn->setEnabled(true);

        ui->SampleConc->setEnabled(true);
        ui->SampleName->setEnabled(true);
        ui->SampleType->setEnabled(true);

        ui->checkBox->setEnabled(true);
        ui->checkBox_2->setEnabled(true);
        ui->checkBox_3->setEnabled(true);
        ui->checkBox_4->setEnabled(true);

        ui->LoadAllBtn->setEnabled(true);
        ui->CancelLoadBtn->setEnabled(true);

        if(doorStatus.get()==0)
        {
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/t10.png);background-color: rgba(0, 0, 0, 0.3);");
        }
        else
        {
            ui->pushButton_3->setStyleSheet("border-image: url(:/pic/picture/t11.png);background-color: rgba(0, 0, 0, 0.3);");
        }
        RefreshSampleInfo();
    }
    tempThread = new GetTempThread();
    connect(this,&SampleWindow::startTempThread,tempThread,&GetTempThread::run);
    ui->SampleConc->setEnabled(false);
    event->accept();
}

QString SampleWindow::GetDateString(int val){
    return QString::number(val).length()==2?QString::number(val): "0"+QString::number(val);
}

void SampleWindow::RefreshSampleInfo(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    QString sql="Select * from SampleInfo";
    query.exec(sql);

    while (query.next()) {

        QList<QString> accessList;
        accessList.clear();
        QSqlQuery accessQuery(db);
        QString accessSql=QString("Select AccessName from SampleAccessInfo where SampleGuid='%1'").arg(query.value("ID").toString());
        accessQuery.exec(accessSql);

        while (accessQuery.next()) {
            accessList.append(accessQuery.value("AccessName").toString());
        }
        QString accessInfo="";
        for (int n=0;n<accessList.length();n++){
            if (accessList[n]=="FAM"){
                QSqlQuery accQuery(db);
                QString info;
                sql="Select Code from ItemCode Where DicCode='7' and IsDefault='1'";
                accQuery.exec(sql);
                while (accQuery.next()) {
                    info=accQuery.value("Code").toString();
                }
                accessInfo+=info+" ";
            }else if(accessList[n]=="VIC"){
                QSqlQuery accQuery(db);
                QString info;
                sql="Select Code from ItemCode Where DicCode='8' and IsDefault='1'";
                accQuery.exec(sql);
                while (accQuery.next()) {
                    info=accQuery.value("Code").toString();
                }
                accessInfo+=info+" ";
            }else if(accessList[n]=="ROX"){
                QSqlQuery accQuery(db);

                QString info;
                sql="Select Code from ItemCode Where DicCode='9' and IsDefault='1'";
                accQuery.exec(sql);
                while (accQuery.next()) {
                    info=accQuery.value("Code").toString();
                }
                accessInfo+=info+" ";
            }else if(accessList[n]=="CY5"){
                QSqlQuery accQuery(db);

                QString info;
                sql="Select Code from ItemCode Where DicCode='10' and IsDefault='1'";
                accQuery.exec(sql);
                while (accQuery.next()) {
                    info=accQuery.value("Code").toString();
                }
                accessInfo+=info+" ";
            }
        }

        QTableWidgetItem *item = new QTableWidgetItem();
        item->setFont(QFont("Arial", 12, QFont::Bold));
        item->setText(query.value("SampleName").toString()+"\n"+accessInfo);
        item->setTextAlignment(Qt::AlignCenter);

        ui->tableWidget->setItem(query.value("RowNum").toInt(),query.value("ColNum").toInt(),item);
        if(query.value("SampleType").toString()=="标准品"){
            TriangleCornerLabel2 *label = new TriangleCornerLabel2();
            ui->tableWidget->setCellWidget(query.value("RowNum").toInt(),query.value("ColNum").toInt(),label);
        }
        else if(query.value("SampleType").toString()=="未知")
        {
            TriangleCornerLabel *label = new TriangleCornerLabel();
            ui->tableWidget->setCellWidget(query.value("RowNum").toInt(),query.value("ColNum").toInt(),label);
        }
        else if(query.value("SampleType").toString()=="阴性")
        {
            TriangleCornerLabel4 *label = new TriangleCornerLabel4();
            ui->tableWidget->setCellWidget(query.value("RowNum").toInt(),query.value("ColNum").toInt(),label);
        }
        else{
            ui->tableWidget->removeCellWidget(query.value("RowNum").toInt(),query.value("ColNum").toInt());
        }

    }

    sql=QString("select "
                "sum( case when sampleType='未知' THEN 1 ELSE 0 END) as UnknownNum,"
                "sum( case when sampleType='标准品' THEN 1 ELSE 0 END) as StandardNum,"
                "sum( case when sampleType='阴性' THEN 1 ELSE 0 END) as NegativeNum "
                "from sampleInfo where experimentGuid='%1' and sampleType<>'' ").arg(MainWindow::experimentGuid);
    query.exec(sql);
    while (query.next()) {
        ui->UnknownNum->setText(query.value("UnknownNum").toString());
        ui->StandardNum->setText(query.value("StandardNum").toString());
        ui->label_3->setText(query.value("NegativeNum").toString());
    }

    if(selectedItems.length()>0){
        foreach(QTableWidgetSelectionRange range,selectedItems){
            ui->tableWidget->setRangeSelected(range,true);
        }
    }
}

void SampleWindow::on_ClearBtn_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;

                sql=QString("Delete from SampleAccessInfo where sampleGuid="
                            "(Select id from SampleInfo where colNum='%1' and rowNum='%2')").arg(QString::number(i),QString::number(j));
                query.exec(sql);

                sql=QString("Update SampleInfo set SampleName='',SampleType='',SampleConc='' where colNum='%1' and rowNum='%2'").arg(QString::number(i),QString::number(j));
                query.exec(sql);
            }
        }
    }
    ui->checkBox->setChecked(false);
    ui->checkBox_2->setChecked(false);
    ui->checkBox_3->setChecked(false);
    ui->checkBox_4->setChecked(false);
    ui->SampleConc->setText("");
    ui->SampleType->setCurrentText("");
    ui->SampleName->setCurrentText("");
    selectedItems.clear();
    RefreshSampleInfo();
}

void SampleWindow::on_LoadAllBtn_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;

                bool canable=true;
                sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='FAM'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                query.exec(sql);
                while (query.next()) {
                    canable=query.value("Result")==0;
                }

                if(canable){
                    sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                "'%1',"
                                "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                "'FAM')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);
                }

                sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='ROX'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);

                query.exec(sql);

                canable=true;
                while (query.next()) {
                    canable=query.value("Result")==0;
                }
                if(canable){
                    sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                "'%1',"
                                "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                "'ROX')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);
                }

                sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='VIC'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                query.exec(sql);

                canable=true;
                while (query.next()) {
                    canable=query.value("Result")==0;
                }
                if(canable){
                    sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                "'%1',"
                                "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                "'VIC')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);
                }

                sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='CY5'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                query.exec(sql);

                canable=true;
                while (query.next()) {
                    canable=query.value("Result")==0;
                }
                if(canable){
                    sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                "'%1',"
                                "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                "'CY5')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);
                }
            }
        }

    }
    ui->checkBox->setChecked(true);
    ui->checkBox_2->setChecked(true);
    ui->checkBox_3->setChecked(true);
    ui->checkBox_4->setChecked(true);
    RefreshSampleInfo();
}

void SampleWindow::on_CancelLoadBtn_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;

                sql=QString("Delete from SampleAccessInfo where sampleGuid="
                            "(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3')").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                query.exec(sql);
            }
        }
    }
    ui->checkBox->setChecked(false);
    ui->checkBox_2->setChecked(false);
    ui->checkBox_3->setChecked(false);
    ui->checkBox_4->setChecked(false);
    RefreshSampleInfo();
}

void SampleWindow::on_SaveBtn_clicked()
{
    QString path=QString("/path/to/default/%1").arg(ui->label_10->text());

    QString filePath = QFileDialog::getSaveFileName(this, "保存", path);

    if(filePath.isEmpty()&&filePath.isNull()){
        return;
    }
    MainWindow::experimentSaveDataPath=filePath + ".wlk";
    backBaseInfo();
}

void SampleWindow::on_BeginBtn_clicked()
{
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    QString sql="Select AmplGuid from ExperimentInfo";
    query.exec(sql);
    QString amplGuid="";
    while (query.next()) {
        amplGuid=query.value("AmplGuid").toString();
    }
    if(amplGuid.isNull()||amplGuid.isEmpty()){
        tcts *tctsWindow = new tcts();
        tctsWindow->infochange("启动实验","info","请选择扩增程序",false,true);
        tctsWindow->show();
        return;
    }

    sql="Select count(*) as Num From SampleInfo Where SampleType='标准品' and SampleConc=''";
    query.exec(sql);
    int noConcNum=0;
    while (query.next()) {
        noConcNum=query.value("Num").toInt();
    }

    if(noConcNum>0){
        sql="Select min(colNum) as colNum,rowNum From SampleInfo where rowNum =( Select min(rowNum) From SampleInfo Where SampleType='标准品' and SampleConc='') and  SampleType='标准品' and SampleConc=''";
        int colNum,RowNum;
        query.exec(sql);
        while (query.next()) {
            colNum=query.value("ColNum").toInt();
            RowNum=query.value("RowNum").toInt();
        }
        ui->tableWidget->setCurrentCell(RowNum,colNum);
        on_tableWidget_cellPressed(RowNum,colNum);
        ui->label_4->show();
        return;
    }
    sql="Select count(*) as Num From SampleInfo where SampleType='标准品'";
    query.exec(sql);
    while (query.next()) {
        MainWindow::isBzsy=query.value("Num")>0;
    }
    if(MainWindow::isBzsy){
        sql="Select count(*) as Num From ("
            "Select sampleGuid,count(AccessName) as Num "
            "From  SampleAccessInfo sa "
            "Join sampleInfo s on sa.SampleGuid=s.ID "
            "group by sampleGuid) where Num<4";
        query.exec(sql);
        bool existsUnreasonableData=false;
        while (query.next()) {
            existsUnreasonableData=query.value("Num")>0;
        }
        if(existsUnreasonableData){
            tcts *tctsWindow = new tcts();
            tctsWindow->infochange("启动实验","info","标准实验需选择全部通道",false,true);
            tctsWindow->show();
            return;
        }
    }



    alertv = new alert();
    alertv->show();
    connect(alertv->ui->pushButton_2,SIGNAL(clicked()),this,SLOT(wlkout()));

}

void SampleWindow::wlkout(){
    alertv->close();
    QString path=QString("/path/to/default/%1").arg(ui->label_10->text());
    QString filePath = QFileDialog::getSaveFileName(this, "保存", path);
    if(filePath.isEmpty()&&filePath.isNull()){
        return;
    }

    MainWindow::experimentSaveDataPath = filePath + ".wlk";

    QFile file(MainWindow::experimentSaveDataPath);

    if(!file.open(QFile::WriteOnly|QFile::Text))
    {
        tcts *tctsWindow = new tcts();
        tctsWindow->infochange("提示","info","请选择正确的文件",false,true);
        tctsWindow->show();
        return;
    }
    //点击确认--执行
    startExperiment();
    disconnect(alertv->ui->pushButton_2,SIGNAL(clicked()),this,SLOT(wlkout()));
}

void SampleWindow::oneMachineStartExperiment(){
    if(MainWindow::startExperiment.get()==1){
        startExperiment();
    }
    if(MainWindow::startExperiment.get()==2){
        QString data="00 00 00 01 00 04";
        QString finalData=QString("%1 %2 55 AA").arg(data,common->GetCrcCheck(data.toLatin1()));
        QString dataLength=common->TenToSixteen(finalData.remove(QRegExp("\\s")).length()/2,4);
        QString head= QString("62 00 00 3A %1 ").arg(dataLength);
        QString result=head+finalData;
        QByteArray sendInfo=common->GetSendData(result);
        tcpClient->ClientSendingData(sendInfo);

        MainWindow::canAnalyData.set(1);
        MainWindow::experimentStatus.set(2);
        this->close();
        emit changeMainWindow();
        logClient->WriteLog("CommLog","发送:\n"+result);

        if(MainWindow::tcpServerStatus.get()==1){
            tcpServer=TcpServer::getInstance();

            QString serverData="62 00 00 3A 00 06 05 01 00 00 55 AA";
            QByteArray finalServerInfo=common->GetSendData(serverData);
            tcpServer->sendData(finalServerInfo);
            tcpServer->closeConnect();

            MainWindow::startExperiment.set(0);
        }
    }
}

void SampleWindow::startExperiment(){
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    MainWindow::tempOrder = 0;

    eqptinfo eqInfo;
    QString samplesum=eqInfo.sampelsumread();
    QString sql="Select count(Distinct s.Id) as Sums from sampleInfo s "
                "Join SampleAccessInfo a on s.Id=a.SampleGuid ";
    query.exec(sql);
    while (query.next()) {
        eqInfo.sampelsumwrite(QString::number(samplesum.toDouble()+query.value("Sums").toDouble()));
    }

    sql=QString("Select * from AmplStep "
                "where "
                "programId=("
                "Select AmplGuid from ExperimentInfo where id='%1') order by StepNum").arg(MainWindow::experimentGuid);
    query.exec(sql);

    QString data="";
    int stepNum=0;
    while (query.next()) {
        QString step=common->TenToSixteen( query.value("StepNum").toInt(),2);
        QString rate=common->TenToSixteen(query.value("Rate").toInt()*100,4);
        QString temp=common->TenToSixteen( query.value("Temperature").toInt()*100,4);
        QString time=common->TenToSixteen( query.value("ExecutionTime").toInt(),4);
        QString cycleNumber=common->TenToSixteen(query.value("CycleNumber").toInt(),2);
        QString cycleNum=common->TenToSixteen( query.value("CycleNum").toInt(),2);
        QString collect=query.value("IsCollect").toString()=="是"?"01":"00";
        QString stepData=QString("%1 %2 %3 %4 %5 %6 %7 ").arg(step,temp,rate,time,cycleNumber,cycleNum,collect);
        //        QString stepData=QString("%1 %2 %3 %4 %5 %6 ").arg(step,temp,time,cycleNumber,cycleNum,collect);

        data+=stepData;
        stepNum++;
    }

    //    QString ConsumableType="00";
    //    sql=QString("Select '0'||Code as Code from ItemCode where Name=( Select ConsumableType from ExperimentInfo) and DicCode='6' ");
    //    query.exec(sql);
    //    while (query.next()) {
    //        ConsumableType=query.value("Code").toString();
    //    }

    QString finalData=QString(
                "00 00 00 01 %1 %4 00 00 %2 "
                "%3 55 AA").arg(common->TenToSixteen(stepNum,2),data,common->GetCrcCheck(data.toLatin1()),"01");
    QString dataInfo=finalData;
    QString dataLength=common->TenToSixteen( finalData.remove(QRegExp("\\s")).length()/2,4);

    QString head= QString("62 00 00 38 %1 ").arg(dataLength);

    QString result=head+dataInfo;
    finalInfo=common->GetSendData(result);

    tcpClient->ClientSendingData(finalInfo);
    logClient->WriteLog("CommLog",result);
    sendNum=0;
    MainWindow::startExperimentStatus.set(2);

}

void SampleWindow::experimentStatusChanged(){
    thread()->sleep(1);
    if(MainWindow::startExperimentStatus.get()==1 && MainWindow::experimentStatus.get()==0){
        if(sendNum<3){
            tcpClient->ClientSendingData(finalInfo);
            logClient->WriteLog("CommLog","发送:\n"+finalInfo);
            sendNum+=1;
            MainWindow::startExperimentStatus.set(2);
        }else{
            MainWindow::startExperiment.set(0);

            if(MainWindow::tcpServerStatus.get()==1){
                tcpServer=TcpServer::getInstance();

                QString serverData="62 00 00 3A 00 06 04 02 00 00 55 AA";
                QByteArray finalServerInfo=common->GetSendData(serverData);
                tcpServer->sendData(finalServerInfo);
                tcpServer->closeConnect();

            }else{
                tcts *tctsWindow = new tcts();
                tctsWindow->infochange("失败","error","启动实验失败,请检查网络连接",false,true);
                tctsWindow->show();
            }
        }
    }
    else if(MainWindow::startExperimentStatus.get()==0 && MainWindow::experimentStatus.get()==0){
        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);

        backBaseInfo();
        QDateTime dateTime;
        QString dateTime_str = dateTime.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
        QString sql= QString("Update ExperimentInfo set Status='运行',RunTime='%2' where id='%1'").arg(MainWindow::experimentGuid,dateTime_str);
        query.exec(sql);

        sql="Delete from FluorescenceData";
        query.exec(sql);

        sql=QString("Delete from FluorescenceLvData");
        query.exec(sql);

        sql=QString("Delete from FluorescenceLvboData");
        query.exec(sql);

        sql=QString("Delete from FluorescenceLogData");
        query.exec(sql);

        sql=QString("Delete from FluorescenceNormalData");
        query.exec(sql);

        sql=QString("Delete from FluorescenceLvboTempTable");
        query.exec(sql);

        sql=QString("Delete from FluorescenceTempTable");
        query.exec(sql);

        sql=QString("Delete from FluorescenceNormalTempTable");
        query.exec(sql);

        sql=QString("Delete from FluorescenceLogTempTable");
        query.exec(sql);

        sql=QString("Delete from FluorescenceResultTable");
        query.exec(sql);

        MainWindow::experimentStatus.set(1);
        MainWindow::experimentStep.set(1);
        MainWindow::experimentCircle.set(0);
        MainWindow::canAnalyData.set(1);
        MainWindow::tempOrder=0;

        if(MainWindow::tcpServerStatus.get()==1){
            tcpServer=TcpServer::getInstance();

            QString serverData="62 00 00 3A 00 06 04 01 00 00 55 AA";
            QByteArray finalServerInfo=common->GetSendData(serverData);
            tcpServer->sendData(finalServerInfo);
            tcpServer->closeConnect();

            MainWindow::startExperiment.set(0);
        }

        emit startTempThread();
        this->close();
        emit changeMainWindow();
    }
}

void SampleWindow::on_checkBox_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;
                if(ui->checkBox->isChecked()){
                    sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='FAM'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);

                    bool canable=true;
                    while (query.next()) {
                        canable=query.value("Result")==0;
                    }
                    if(canable){
                        sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                    "'%1',"
                                    "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                    "'FAM')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    }
                }
                else
                {
                    sql=QString("Delete from SampleAccessInfo "
                                "Where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='FAM'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                }
                query.exec(sql);
            }
        }
    }
    RefreshSampleInfo();
}

void SampleWindow::on_checkBox_2_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;
                if(ui->checkBox_2->isChecked()){
                    sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='VIC'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);

                    bool canable=true;
                    while (query.next()) {
                        canable=query.value("Result")==0;
                    }
                    if(canable){
                        sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                    "'%1',"
                                    "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                    "'VIC')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    }
                }
                else
                {
                    sql=QString("Delete from SampleAccessInfo "
                                "Where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='VIC'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                }
                query.exec(sql);
            }
        }
    }
    RefreshSampleInfo();
}

void SampleWindow::on_checkBox_3_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;
                if(ui->checkBox_3->isChecked()){
                    sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='CY5'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);

                    bool canable=true;

                    while (query.next()) {
                        canable=query.value("Result")==0;
                    }
                    if(canable){
                        sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                    "'%1',"
                                    "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                    "'CY5')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    }
                }
                else
                {
                    sql=QString("Delete from SampleAccessInfo "
                                "Where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='CY5'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                }
                query.exec(sql);
            }
        }
    }
    RefreshSampleInfo();
}

void SampleWindow::on_checkBox_4_clicked()
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;
                if(ui->checkBox_4->isChecked()){
                    sql=QString("Select count(*) Result from SampleAccessInfo where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='ROX'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);

                    query.exec(sql);

                    bool canable=true;
                    while (query.next()) {
                        canable=query.value("Result")==0;
                    }
                    if(canable){
                        sql=QString("Insert into SampleAccessInfo(ID,SampleGuid,AccessName) values("
                                    "'%1',"
                                    "(Select id from SampleInfo where colNum='%2' and rowNum='%3' and experimentGuid='%4'),"
                                    "'ROX')").arg(common->GetGuid(),QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    }
                }
                else
                {
                    sql=QString("Delete from SampleAccessInfo "
                                "Where SampleGuid=(Select id from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3') and AccessName='ROX'").arg(QString::number(i),QString::number(j),MainWindow::experimentGuid);
                }
                query.exec(sql);
            }
        }
    }
    RefreshSampleInfo();
}

void SampleWindow::on_SampleName_editTextChanged(const QString &arg1)
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;
                sql=QString("Update SampleInfo set SampleName='%1' where colNum='%2' and rowNum='%3'").arg(arg1,QString::number(i),QString::number(j));
                query.exec(sql);
            }
        }
    }
    RefreshSampleInfo();
}

void SampleWindow::on_SampleType_activated(const QString &arg1)
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }

    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);
    foreach(QTableWidgetSelectionRange range,selectedItems){
        for(int i=range.leftColumn();i<=range.rightColumn();i++){
            for (int j=range.topRow();j<=range.bottomRow();j++) {
                QString sql;
                sql=QString("Update SampleInfo set SampleType='%1' where colNum='%2' and rowNum='%3' and experimentGuid='%4'").arg(arg1,QString::number(i),QString::number(j),MainWindow::experimentGuid);
                query.exec(sql);
            }
        }
    }
    if(arg1=="标准品"){
        ui->label_4->show();
        ui->SampleConc->setDisabled(false);
        ui->SampleConc->setStyleSheet("background-color: rgb(255, 255, 255);");
    }else{
        ui->label_4->hide();
        ui->SampleConc->setDisabled(true);
        ui->SampleConc->clear();
        ui->SampleConc->setStyleSheet("background-color: rgb(190, 190, 190);");
    }
    RefreshSampleInfo();
}

void SampleWindow::on_SampleConc_textEdited(const QString &arg1)
{
    QString conc=ui->SampleConc->text();
    if(!conc.isNull()&&!conc.isEmpty()){
        if(ui->tableWidget->selectedRanges().length()>0){
            selectedItems = ui->tableWidget->selectedRanges();
        }

        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        foreach(QTableWidgetSelectionRange range,selectedItems){
            for(int i=range.leftColumn();i<=range.rightColumn();i++){
                for (int j=range.topRow();j<=range.bottomRow();j++) {
                    QString sql;
                    sql=QString("Update SampleInfo set SampleConc='%1' where colNum='%2' and rowNum='%3' and experimentGuid='%4'").arg(conc,QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);
                }
            }
        }
        ui->label_4->hide();
    }else{
        if(ui->tableWidget->selectedRanges().length()>0){
            selectedItems = ui->tableWidget->selectedRanges();
        }

        QSqlDatabase db = dbHelper::openConnection();
        QSqlQuery query(db);
        foreach(QTableWidgetSelectionRange range,selectedItems){
            for(int i=range.leftColumn();i<=range.rightColumn();i++){
                for (int j=range.topRow();j<=range.bottomRow();j++) {
                    QString sql;
                    sql=QString("Update SampleInfo set SampleConc='%1' where colNum='%2' and rowNum='%3' and experimentGuid='%4'").arg(conc,QString::number(i),QString::number(j),MainWindow::experimentGuid);
                    query.exec(sql);
                }
            }
        }
        ui->label_4->show();
    }

}

void SampleWindow::on_SampleConc_editingFinished()
{
    RefreshSampleInfo();
}

void SampleWindow::on_pushButton_7_clicked()
{
    if(MainWindow::experimentStatus.get()==4){
        this->close();
        emit changeExpInfoWindow();
    }
    else
    {
        this->close();
        emit changeMainWindow();
    }
}

void SampleWindow::on_pushButton_8_clicked()
{
    if(MainWindow::experimentStatus.get()==4){
        this->close();
        emit changeDataAnalyWindow();
    }
    else
    {
        this->close();
        emit changeExpeWindow();
    }
}

void SampleWindow::changeToMainWindow(){
    if(MainWindow::experimentStatus.get()==2||MainWindow::experimentStatus.get()==3 ||MainWindow::tcpServerStatus.get()==1){
        this->close();
        emit changeMainWindow();
    }
}

void TriangleCornerLabel::paintEvent(QPaintEvent *event)
{
    QLabel::paintEvent(event);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    // 设置三角形的颜色和样式
    painter.setPen(Qt::NoPen);
    painter.setBrush(QColor("#4EBE77")); // 设置填充颜色为绿色

    // 计算三角形的顶点位置
    QPoint p1(0, 0); // 左上角顶点
    QPoint p2(24, 0); // 右上角顶点
    QPoint p3(0, 24); // 左下角顶点

    // 绘制三角形
    QPainterPath path;
    path.moveTo(p1);
    path.lineTo(p2);
    path.lineTo(p3);
    path.closeSubpath();
    painter.drawPath(path);

    // 设置字体样式和大小
    painter.setPen(Qt::white); // 设置文本颜色为白色
    // 假设字体大小是三角形大小的一半（或根据需要调整）
    painter.setFont(QFont("Arial", 8, QFont::Bold));
    // 计算文本位置
    QPoint textTopLeft(3,12); // 确保文本在三角形内部并靠近上边缘
    // 绘制文本
    painter.drawText(textTopLeft, "U");
}

void TriangleCornerLabel2::paintEvent(QPaintEvent *event)
{
    QLabel::paintEvent(event);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    // 设置三角形的颜色和样式
    painter.setPen(Qt::NoPen);
    painter.setBrush(QColor("#FFBC0D"));

    // 计算三角形的顶点位置
    QPoint p1(0, 0); // 左上角顶点
    QPoint p2(24, 0); // 右上角顶点
    QPoint p3(0, 24); // 左下角顶点

    // 绘制三角形
    QPainterPath path;
    path.moveTo(p1);
    path.lineTo(p2);
    path.lineTo(p3);
    path.closeSubpath();
    painter.drawPath(path);

    // 设置字体样式和大小
    painter.setPen(Qt::white); // 设置文本颜色为白色
    // 假设字体大小是三角形大小的一半（或根据需要调整）
    painter.setFont(QFont("Arial", 8, QFont::Bold));
    // 计算文本位置
    QPoint textTopLeft(3,12); // 确保文本在三角形内部并靠近上边缘
    // 绘制文本

    //u 未知 s标准
    painter.drawText(textTopLeft, "S");
}

void TriangleCornerLabel4::paintEvent(QPaintEvent *event)
{
    QLabel::paintEvent(event);

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    // 设置三角形的颜色和样式
    painter.setPen(Qt::NoPen);
    painter.setBrush(QColor("#0DE0FF"));

    // 计算三角形的顶点位置
    QPoint p1(0, 0); // 左上角顶点
    QPoint p2(24, 0); // 右上角顶点
    QPoint p3(0, 24); // 左下角顶点

    // 绘制三角形
    QPainterPath path;
    path.moveTo(p1);
    path.lineTo(p2);
    path.lineTo(p3);
    path.closeSubpath();
    painter.drawPath(path);

    // 设置字体样式和大小
    painter.setPen(Qt::white); // 设置文本颜色为白色
    // 假设字体大小是三角形大小的一半（或根据需要调整）
    painter.setFont(QFont("Arial", 8, QFont::Bold));
    // 计算文本位置
    QPoint textTopLeft(3,12); // 确保文本在三角形内部并靠近上边缘
    // 绘制文本

    //u 未知 s标准
    painter.drawText(textTopLeft, "N");
}

void SampleWindow::on_tableWidget_cellPressed(int row, int column)
{
    if(ui->tableWidget->selectedRanges().length()>0){
        selectedItems = ui->tableWidget->selectedRanges();
    }
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    ui->SampleName->blockSignals(true);
    QString currentSampleGuid;
    QString sql=QString("Select * from SampleInfo where colNum='%1' and rowNum='%2' and experimentGuid='%3'").arg(QString::number(column),QString::number(row),MainWindow::experimentGuid);

    query.exec(sql);
    while (query.next()) {
        currentSampleGuid=query.value("ID").toString();

        QString conc=query.value("SampleConc").toString();
        ui->SampleName->setCurrentText(query.value("SampleName").toString());

        if(query.value("SampleType").toString().isNull()||query.value("SampleType").toString().isEmpty()){
            ui->SampleType->setCurrentIndex(-1);
        }else {
            ui->SampleType->setCurrentText(query.value("SampleType").toString());
        }
        if(query.value("SampleType").toString()=="标准品"){
            ui->label_8->setText("<font color=red>*</font><font>浓度</font>");
            ui->SampleConc->setDisabled(false);
            ui->SampleConc->setStyleSheet("background-color: rgb(255, 255, 255);");
            if(conc.isNull()||conc.isEmpty()){
                ui->label_4->show();
            }else{
                ui->label_4->hide();
            }
        }else{
            ui->label_4->hide();

            ui->label_8->setText("<font>浓度</font>");
            ui->SampleConc->setDisabled(true);
            ui->SampleConc->clear();
            ui->SampleConc->setStyleSheet("background-color: rgb(190, 190, 190);");
        }

        ui->SampleConc->setText(conc);
    }

    sql=QString("Select AccessName from SampleAccessInfo where SampleGuid='%1'").arg(currentSampleGuid);
    query.exec(sql);

    QList<QString> accessList;
    accessList.clear();
    while (query.next()) {
        accessList.append(query.value("AccessName").toString());
    }

    ui->checkBox->setChecked(accessList.contains("FAM"));
    ui->checkBox_2->setChecked(accessList.contains("VIC"));
    ui->checkBox_4->setChecked(accessList.contains("ROX"));
    ui->checkBox_3->setChecked(accessList.contains("CY5"));

    ui->SampleName->blockSignals(false);
}

void SampleWindow::backBaseInfo(){
    //数据存储
    QSqlDatabase db = dbHelper::openConnection();
    QSqlQuery query(db);

    //1.扩增程序
    QString sql=QString("Select * from AmplProgram "
                        "where "
                        "ID=("
                        "Select AmplGuid from ExperimentInfo where id='%1')").arg(MainWindow::experimentGuid);

    query.exec(sql);
    QString addSql;
    while (query.next()) {
        addSql=QString("Insert into AmplProgramTemp values('%1','%2','%3','%4','%5','%6','%7');").arg(query.value("ID").toString(),query.value("IsDefault").toString(),
                                                                                                      query.value("ProgramName").toString(),query.value("Duration").toString(),
                                                                                                      query.value("StepNum").toString(),query.value("CreateDate").toString(),
                                                                                                      query.value("Memo").toString());
    }
    QFile file(MainWindow::experimentSaveDataPath);

    file.open(QFile::WriteOnly|QFile::Text);

    QTextStream out(&file);  //QTextStream会自动将 Unicode 编码同操作系统的编码进行转换
    out<<"cardType\n";
    out<<addSql+"\n";

    sql=QString("Select * from AmplStep "
                "where "
                "programId=("
                "Select AmplGuid from ExperimentInfo where id='%1') order by StepNum").arg(MainWindow::experimentGuid);
    query.exec(sql);
    while (query.next()) {
        addSql=QString("Insert into AmplStepTemp values('%1','%2','%3','%4','%5','%6','%7','%8','%9');").arg(query.value("ID").toString(),query.value("ProgramId").toString(),
                                                                                                             query.value("StepNum").toString(),query.value("Temperature").toString(),
                                                                                                             query.value("ExecutionTime").toString(),query.value("Rate").toString(),
                                                                                                             query.value("IsCollect").toString(),query.value("CycleNumber").toString(),
                                                                                                             query.value("CycleNum").toString());
        out<<addSql+"\n";
    }

    sql="Select * from SampleInfo ";
    query.exec(sql);
    while (query.next()) {
        addSql=QString("Insert into SampleInfo values('%1','%2','%3','%4','%5','%6','%7','%8');").arg(query.value("ID").toString(),query.value("ExperimentGuid").toString(),
                                                                                                      query.value("ColNum").toString(),query.value("RowNum").toString(),
                                                                                                      query.value("SampleName").toString(),query.value("SampleType").toString(),
                                                                                                      query.value("SampleConc").toString(),query.value("Pos").toString());
        out<<addSql+"\n";
    }

    sql="Select * from SampleAccessInfo ";
    query.exec(sql);
    while (query.next()) {
        addSql=QString("Insert into SampleAccessInfo values('%1','%2','%3','%4');").arg(query.value("ID").toString(),query.value("SampleGuid").toString(),
                                                                                        query.value("AccessName").toString(),query.value("CtValue").toString());
        out<<addSql+"\n";
    }

    sql="Select * from ExperimentInfo ";
    query.exec(sql);
    while (query.next()) {
        addSql=QString("Insert into ExperimentInfo values('%1','%2','%3','%4','%5','%6','%7','%8','%9');").arg(query.value("ID").toString(),query.value("ExperimentName").toString(),
                                                                                                               query.value("AmplGuid").toString(),query.value("Code").toString(),
                                                                                                               query.value("System").toString(),query.value("RunTime").toString(),
                                                                                                               query.value("Status").toString(),query.value("FinishTime").toString(),
                                                                                                               query.value("ConsumableType").toString());
        out<<addSql+"\n";
    }
    file.close();
}




